package cn.ld.module.system.dal.mapper.social;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.socail.vo.user.SocialUserPageInVO;
import cn.ld.module.system.dal.entity.social.SocialUserEntity;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SocialUserMapper extends BaseMapperX<SocialUserEntity> {

    default SocialUserEntity selectByTypeAndCodeAnState(Integer type, String code, String state) {
        return selectOne(new LambdaQueryWrapper<SocialUserEntity>()
                .eq(SocialUserEntity::getType, type)
                .eq(SocialUserEntity::getCode, code)
                .eq(SocialUserEntity::getState, state));
    }

    default SocialUserEntity selectByTypeAndOpenid(Integer type, String openid) {
        return selectOne(new LambdaQueryWrapper<SocialUserEntity>()
                .eq(SocialUserEntity::getType, type)
                .eq(SocialUserEntity::getOpenid, openid));
    }

    default PageResult<SocialUserEntity> selectPage(SocialUserPageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<SocialUserEntity>()
                .eqIfPresent(SocialUserEntity::getType, inVO.getType())
                .likeIfPresent(SocialUserEntity::getNickname, inVO.getNickname())
                .likeIfPresent(SocialUserEntity::getOpenid, inVO.getOpenid())
                .betweenIfPresent(SocialUserEntity::getCreateTime, inVO.getCreateTime())
                .orderByDesc(SocialUserEntity::getId));
    }

}
